package com.jdzy.student.controller;

import com.jdzy.model.common.vos.Result;
import com.jdzy.model.student.dtos.CompetitionDeleteDto;
import com.jdzy.model.student.dtos.CompetitionDto;
import com.jdzy.student.service.CompetitionService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@Slf4j
@RequestMapping("api/competition")
@Api(value = "竞赛的controller类")
public class CompetitionController {
    @Autowired
    private CompetitionService competitionService;

    /**
     * 新增竞赛信息
     * @param competitionDto
     * @return
     */
    @PostMapping("saveCompetition")
    public Result saveCompetition(@RequestBody CompetitionDto competitionDto){
        log.info("新增竞赛信息,参数:{}",competitionDto);
        return competitionService.saveCompetition(competitionDto);
    }

    /**
     * 获取竞赛信息
     * @param stuId
     * @return
     */
    @PostMapping("getCompetitionInfo/{stuId}/{page}/{size}")
    public Result getCompetitionInfo(@PathVariable String stuId,@PathVariable Integer page
            ,@PathVariable Integer size,@RequestBody CompetitionDto competitionDto){
        log.info("分页获取竞赛信息,参数:{},{},{},{}",stuId,page,size,competitionDto);
        return competitionService.getCompetitionInfo(stuId, page, size,competitionDto);
    }

    /**
     * 删除竞赛信息
     * @param stuId
     * @param competitionDeleteDto
     * @return
     */
    @DeleteMapping("deleteCompetition/{stuId}")
    public Result deleteCompetition(@PathVariable String stuId, @RequestBody CompetitionDeleteDto competitionDeleteDto){
        log.info("删除竞赛信息,参数:{},{}",stuId,competitionDeleteDto);
        return competitionService.deleteCompetition(stuId,competitionDeleteDto);
    }


    /**
     * 修改竞赛信息表
     * @param competitionDto
     * @return
     */
    @PostMapping("updateCompetition")
    public Result updateCompetition(@RequestBody CompetitionDto competitionDto){
        log.info("修改竞赛信息表,参数:{}",competitionDto);
        return competitionService.updateCompetition(competitionDto);
    }

}
